package com.project.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.RoleBean;
import com.project.mapper.IRoleMapper;
import com.project.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class RoleServiceImpl implements IRoleService {
    @Autowired
    private IRoleMapper mapper;
    @Override
    public List<RoleBean> findAll() {
        return mapper.findAll();
    }

    @Override
    public PageInfo<RoleBean> cutAll(int pageNO) {
        PageHelper.startPage(pageNO, PAGESIZE);
        PageInfo<RoleBean> pageInfo = PageInfo.of(mapper.findAll());
        return pageInfo;
    }

    @Override
    public void addRole(RoleBean role, int[] gradeArray) {
        mapper.addRole(role);
        mapper.addGradeList(role.getId(), gradeArray);
    }

    @Override
    public void delRole(int id) {
        mapper.delRole(id);
    }

    @Override
    public RoleBean findById(int id) {
        return mapper.findById(id);
    }

    @Override
    public void updateRoleGrade(int id, int[] gradeArray) {
        mapper.updateRoleGrade(id, gradeArray);
    }
}
